/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;

/**
 *
 * @author user
 */
public class ChatUser extends ArrayList<Chat> {

    public int userId;

    public ChatUser(int userId) {
        super();
        this.userId = userId;
    }

    public ArrayList<Chat> find(int lastId, int senderId, String type) {
        ArrayList<Chat> chats = new ArrayList<Chat>();
        Chat chat;
        lastId++;

        while (lastId < this.size()) {
            chat = this.get(lastId++);
            if (type.equals("room") || chat.senderId == senderId) {
                chats.add(chat);
            }
        }

        return chats;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("[");

        for (int i = 0; i < this.size(); ++i) {
            sb.append(this.get(i).toString());
            sb.append(", ");
        }

        sb.append(']');

        return sb.toString();
    }
}
